﻿<%@ Page Title="" Language="C#" MasterPageFile="~/GUI/MasterPage.master" AutoEventWireup="true" CodeFile="AddNewBook.aspx.cs" Inherits="Home_AddNewBook" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">    
    <script type="text/javascript">
        $(function() {
            $(".CheckBox input[type='checkbox']").click(function() {
                if (this.checked == true) {
                    $(this).attr("value", "checked");
                } else {
                    $(this).attr("value", "");
                }
            });
            clearImageContent();
            clearDataContent();

        });

        function CheckNull() 
        {
            var Name = document.getElementById('txtName');
            var NameError = document.getElementById('ErrorName');
            if(Name.value=="") 
            {
                NameError.innerHTML = '<%=Language["ErrorNull"] %>';
                return false;
            } else if (!validText(Name.value)) {
                NameError.innerHTML = '<%=Language["ErrNotacceptScharacters"] %>';
                return false;
            } else {
                return true;
            }
        }
        //error
        function uploadImageError(sender, args) {          
            var ErrorUploadImage = document.getElementById('ErrorUploadImage');
            if (args.get_errorMessage() == '$common is undefined') {
                ErrorUploadImage.style.color = "green";
                ErrorUploadImage.innerHTML = "Upload file successful...";
            }
            else {
                ErrorUploadImage.style.color = "red";
                ErrorUploadImage.innerHTML = "Upload file fail...";
            }
               
        }
        //error
        function uploadDataError(sender,args) {

            var ErrorUploadData = document.getElementById('ErrorUploadData');
            if (args.get_errorMessage() == '$common is undefined') 
            {  
                 ErrorUploadData.style.color = "green";
                ErrorUploadData.innerHTML = "Upload file successful..."; 
            }
            else
            {
                ErrorUploadData.style.color = "red";
                ErrorUploadData.innerHTML = "File upload fail...";
            }
            
        }
        //upload data complete
        function uploadImageComplete(sender) {            
            var ErrorUploadImage = document.getElementById('ErrorUploadImage');
            ErrorUploadImage.style.color = "green";
            ErrorUploadImage.innerHTML = "Upload file successful...";
        }     
        //upload data complete
        function uploadDataComplete(sender) {
            var ErrorUploadData = document.getElementById('ErrorUploadData');
            ErrorUploadData.style.color = "green";
            ErrorUploadData.innerHTML = "Upload file successful...";
        }
        
        //clear content of upload image
        function clearImageContent() {          

            var AsyncFileUpload = $get("<%=upImage.ClientID%>");

            var txts = AsyncFileUpload.getElementsByTagName("input");

            for (var i = 0; i < txts.length; i++) {

                if (txts[i].type == "text") {

                    txts[i].value = "";

                    txts[i].style.backgroundColor = "white";
                }

            }
        }
        //clear content of upload data
        function clearDataContent() {

            var AsyncFileUpload = $get("<%=upData.ClientID%>");

            var txts = AsyncFileUpload.getElementsByTagName("input");

            for (var i = 0; i < txts.length; i++) {

                if (txts[i].type == "text") {

                    txts[i].value = "";

                    txts[i].style.backgroundColor = "white";
                }

            }

        }
        //check special character
        function validText(value) {
            var chaos = new Array("'", "~", "@", "#", "$", "%", "^", "&", "*", ";", "/", "\\", "|", "<", ">");
            var sum = chaos.length;
            for (var i in chaos) { if (!Array.prototype[i]) { sum += value.lastIndexOf(chaos[i]) } }
            if (sum) {
                return false;
            }
            return true;
        }
    </script>

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <div class="First">
        <div class="IconTitle"><img src="../Images/icon_title.png"/></div>
        <div class="Title"><%= Language[title] %></div>
    </div>
    <div class="Second">
        <div id="wrapper">
        <div class="BookItem1">
            <div class="ClassLabel"><%= Language["Name"] %></div>
            <input type="text" value="<%=currentBook.Name %>" name="txtName" id="txtName"/>
            <label class="ClassError1" id="ErrorName"></label>
        </div>
        <div class="BookItem3">
            <div class="ClassLabel"><%= Language["Image"] %></div>
            <div style="float: left; width: 460px; position: relative; margin-left: -47px;margin-top:2px; ">                            
                <asp:AsyncFileUpload ID="upImage" OnClientUploadError="uploadImageError"
                    OnClientUploadComplete="uploadImageComplete"
                    runat="server" UploaderStyle="Modern" 
                    UploadingBackColor="#CCFFFF" 
                    ThrobberID="myThrobber" />                
                <asp:Image ID="myThrobber" runat="server" ImageUrl = "~/images/loading1.gif" /> 
            </div>
            <label class="ClassError1" id="ErrorUploadImage"></label>            
        </div>
        <div class="BookItem3">
            <div class="ClassLabel"><%= Language["FileData"] %></div>
            <div style="float: left; width: 460px; position: relative; margin-left: -47px; ">                            
               <asp:AsyncFileUpload ID="upData" OnClientUploadError="uploadDataError"
                    OnClientUploadComplete="uploadDataComplete" 
                    runat="server" UploaderStyle="Modern" 
                    UploadingBackColor="#CCFFFF" 
                    ThrobberID="Image1" />                
                <asp:Image ID="Image1" runat="server" ImageUrl = "~/images/loading1.gif" />
            </div>
            <label class="ClassError1" id="ErrorUploadData"></label>
        </div>
        <div class="BookItem1">
            <div class="ClassLabel"><%= Language["Description"]%></div>
            <textarea name="txtDescription"><%=currentBook.Description%></textarea>
        </div>
        <div class="BookItem2">
            <div class="ClassLabel"><%= Language["Platform"]%></div>
            <div class="CheckBox">
                <%
                    for (int i = 0; i < listPlatform.Count; i = i + 1)
                    {
                %>
                <div class="ItemCheckbox">
                    <input type="checkbox" id="<%=listPlatform[i].ID%>" name="platform_<%=listPlatform[i].ID%>" <%=isCheckPlatform(listPlatform[i].ID) %> value="<%=isCheckPlatform(listPlatform[i].ID) %>"/><label for="Ios"><%=listPlatform[i].Name%></label>
                </div>
                <% 
                    }
                %>
            </div>
        </div>
        <div class="BookItem4">
            <asp:Button ID="btnCreate" runat="server" Text="Button" CssClass="BtnCreate" 
                onclick="btnCreate_Click" OnClientClick="return CheckNull()"/>
        </div>
        </div>            
    </div>
</asp:Content>

